package com.solidumgame.martillo.tablewood
{
	import com.pblabs.engine.entity.EntityComponent;
	import com.solidumgame.martillo.tablewood.events.TableWoodGenericEvent;
	
	import flash.media.Sound;
	import flash.net.URLRequest;

	public class TableWoodSoundComponent extends EntityComponent
	{
			private var sound:Sound;
			private var url:URLRequest;
			
			public function TableWoodSoundComponent()
			{
			}
				
			override protected function onAdd():void{
				super.onAdd();
				owner.eventDispatcher.addEventListener(TableWoodGenericEvent.TABLEWOOD_TRHOW_ENTER,soundTableIn);
				owner.eventDispatcher.addEventListener(TableWoodGenericEvent.TABLEWOOD_TRHOW_EXIT,soundTableOut);
			}
			
			override protected function onRemove():void{
				super.onRemove();
				owner.eventDispatcher.removeEventListener(TableWoodGenericEvent.TABLEWOOD_TRHOW_ENTER,soundTableIn);
				owner.eventDispatcher.removeEventListener(TableWoodGenericEvent.TABLEWOOD_TRHOW_EXIT,soundTableOut);
				
			}
			
			public function soundTableIn(e:TableWoodGenericEvent):void{
				url = new URLRequest("../assets/sounds/WoodInSound.mp3");
				sound = new Sound(url);
				sound.play(0,0);
			}
			
			public function soundTableOut(e:TableWoodGenericEvent):void{
				url = new URLRequest("../assets/sounds/WoodOutSound.mp3");
				sound = new Sound(url);
				sound.play(0,0);
			}
		}
	}